package com.cldz.service;

import com.cldz.common.dto.req.DevAlarmConditionDto;
import com.cldz.common.dto.res.DevAlarmConditionResDto;
import com.cldz.utils.BeanCopyUtil;
import com.cldz.dao.DevAlarmConditionMapper;
import com.cldz.entity.DeviceAlarmCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ Author     ：lixiao.
 * @ Date       ：Created in 11:15 2018/12/19
 * @ Description：
 * @ Modified By：
 */
@Service("devAlarmConditionService")
public class DevAlarmConditionService {

    @Autowired
    private DevAlarmConditionMapper devAlarmConditionMapper;

    public List<DevAlarmConditionResDto> getBaseAlarmConList(DevAlarmConditionDto devAlarmConditionDto){
        List<DeviceAlarmCondition> baseAlarmConList = devAlarmConditionMapper.getBaseAlarmConList(devAlarmConditionDto);
        return copyListBean(baseAlarmConList);
    }


    public List<DevAlarmConditionResDto> getAlarmConList(DevAlarmConditionDto devAlarmConditionDto) {
        List<DeviceAlarmCondition> list = devAlarmConditionMapper.getAlarmConList(devAlarmConditionDto);
        return copyListBean(list);
    }


    private List<DevAlarmConditionResDto> copyListBean(List<DeviceAlarmCondition> devListByTypeID) {
        List<DevAlarmConditionResDto> list = new ArrayList<>();
        for (DeviceAlarmCondition device : devListByTypeID) {
            DevAlarmConditionResDto dto = new DevAlarmConditionResDto();
            BeanCopyUtil.copyPropertiesIgnoreNull(device, dto);
//            BeanUtils.copyProperties(device, dto);
            list.add(dto);
        }
        return list;
    }


}
